$(document).ready(function () {
    $('#down').click(down);
    initializationImage();
})

// 初始化图片
function initializationImage(){
    $.ajax({
        type: "GET",
        url: "/img",
        data: "",
        dataType: "json",
        success: function(data){
            if (data.status === "200"){
                $('#img').empty();   //清空resText里面的所有内容
                $('#img').html(data.data);
            }else{
                alert(data.error)
            }

        },
        error:function(XMLHttpRequest, textStatus, errorThrown){
            alert(XMLHttpRequest.status);
            alert(XMLHttpRequest.readyState);
        }
    });
}


// -----------------------------------------------------------------------------------------------------------
// 请求现在接口
function down() {
    var param={};
    postDownLoadFile({
        url:'/down',
        data:param,
        method:'post'
    });
}

var postDownLoadFile = function (options) {
    var config = $.extend(true, {method: 'post'}, options);
    var $iframe = $('<iframe id="down-file-iframe" />');
    var $form = $('<form target="down-file-iframe" method="' + config.method + '" />');
    $form.attr('action', config.url);
    for (var key in config.data) {
        $form.append('<input type="hidden" name="' + key + '" value="' + config.data[key] + '" />');
    }
    $iframe.append($form);
    $(document.body).append($iframe);
    $form[0].submit();
    $iframe.remove();
}
// -----------------------------------------------------------------------------------------------------------
